{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b9723caf",
   "metadata": {},
   "source": [
    "\n",
    "* 日期：2022-10-12 \\ weeek8(周三)\n",
    "* 课程：python\n",
    "\n",
    "## 本周知识点\n",
    "> 1.有序的数据结构-字符串\n",
    ">> 1.字符串的基本概念（回顾）\n",
    ">>> 1.single quotes:'allows:\n",
    "\n",
    ">> 2.字符串的性质和方法  \n",
    "> 2.有序的数据结构-列表"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "35a0b10e",
   "metadata": {},
   "source": [
    "## 1.字符串的性质和方法  \n",
    "\n",
    "> 1.字符串的有序性  \n",
    "\n",
    "> 2.字符串是有长度的  \n",
    ">> 1.使用len（）检查字符串的长度  \n",
    "* 字符串的基础方法  \n",
    "> 1.字符串的取值 ：str[index]  \n",
    "> 2.字符串的切片 ：str[start,stop],stop取不到  \n",
    "> 3.字符串的拼接： +  \n",
    "> 4.in检查成员是否存在  \n",
    "* 字符串的一般方法（function/Methods 函数/方法）  \n",
    "> 1.isdigit()\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "2314cbdb",
   "metadata": {},
   "outputs": [],
   "source": [
    "text = \"广州南方学院团委\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "6b6c45e2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7860b4a1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'州'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "11847c0c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'委'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "c4bb7d75",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "string index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_23136/4266458267.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mtext\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m100\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m: string index out of range"
     ]
    }
   ],
   "source": [
    "text[100]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "e1979d24",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(text)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8ba2095d",
   "metadata": {},
   "source": [
    "####  in检查"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "60eabeb0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0] + text[1] + text[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "77307081",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0:6]   #等价于text[:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "090fcfc3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'院团'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-3:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "17a1372f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'团委'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "88d265dc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'委'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "3d4a8f18",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"广州\"in text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "de280288",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3 * text.count(\"广州\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "01538e3c",
   "metadata": {},
   "source": [
    "## isdigint"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "ac82bec7",
   "metadata": {},
   "outputs": [],
   "source": [
    "age_1 = 19\n",
    "age_2 = \"19\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "1f78dc65",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "can't use starred expression here (Temp/ipykernel_23136/80326722.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"C:\\Users\\1\\AppData\\Local\\Temp/ipykernel_23136/80326722.py\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m    * isdigint()\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m can't use starred expression here\n"
     ]
    }
   ],
   "source": [
    "* isdigint()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "0a92242d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19 <class 'int'>\n",
      "19 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(age_1,type(age_1))\n",
    "print(age_2,type(age_2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "898cfe29",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "38\n"
     ]
    }
   ],
   "source": [
    "if age_2.isdigit():\n",
    "    print(age_1 + int(age_2))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "61e95ccb",
   "metadata": {},
   "source": [
    "## 有序的数据结构-列表  \n",
    "\n",
    "* 1.列表的概念和基本性质  \n",
    "> 1.Python knows a number of compound data types, used to group together other values. The most versatile is the list, which can be written as a list of comma-separated values (items) between square brackets. Lists might contain items of different types, but usually the items all have the same type.  \n",
    "\n",
    "* 2.列表的一般方法（如何学习）  \n",
    "> 1.使用.Tab键查看列表的方法  \n",
    "> 2.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fbfb2340",
   "metadata": {},
   "source": [
    "### 2.1 列表的性质\n",
    "\n",
    "* 和字符串的运算法则完全一致  \n",
    "* 注意：字符串是对字符进行操作，列表是对items元素进行操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "8b0e1181",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 列表的形式\n",
    "squares = [1,4,9,16,25]  #列表里面放数值\n",
    "squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "7b770826",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares[4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "2acc2758",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "4 in squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "468923ab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'lucy', 'rose', 'lisa']"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"jack\",\"lucy\",\"rose\",\"lisa\"] #列表里面放字符串  # 0, 1, 2, 3\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "79fe9049",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 18, '李华', 20]"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "info = [\"jack\",18,\"李华\",20]\n",
    "info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "a55bf8f2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 'jack', 'lucy', 'rose', 'lisa']"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares + names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "aa1e80f9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2 * squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "e1011ae9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['lucy', 'rose']"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[1:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "f9fe9291",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'lucy']"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[0:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "048cc955",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['rose', 'lisa']"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[-2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "3c9d6f73",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'rose']"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 去除“jack”，“rose”用切片的方法\n",
    "names[:3:2]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c2a2cc9d",
   "metadata": {},
   "source": [
    "* 2.列表的一般方法（如何学习）  \n",
    "> 1,增加  \n",
    "> 2.删除  \n",
    "> 3.改  \n",
    "> 4.查：in  \n",
    "\n",
    "* 列表的学习方法(步骤）\n",
    "> 1.使用.Tab键查看列表的方法  \n",
    "> 2.使用help（查看方法的使用规则）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "b1b5bdb7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(object, /) method of builtins.list instance\n",
      "    Append object to the end of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.append)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "e8588020",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append(\"Lihua\")  #append是指增加括号里的元素到末尾，列表是有序的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "63bea603",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['jack', 'lucy', 'rose', 'lisa', 'Lihua']"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7f3350da",
   "metadata": {},
   "source": [
    "## 作业：\n",
    "* 列表的方法尝试所有的方法  \n",
    "* 总结列表的方法学习心得（表格形式总结）  \n",
    "| 列表的方法    |  description  |  使用方法| 备注|\n",
    "| ----------------|--------|--------|------------|\n",
    "|append"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ef27c3be",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b798bfc8",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
